﻿@model Gfw.Web.Models.User.UserSecurityQuestionModel
@{
    ViewBag.Title = "修改密保问题";
    Layout = "~/Views/Shared/_LayoutContent.cshtml";
}

<script>
    $(document).ready(function () {
        var q1 = "您母亲的姓名是？", q2 = "您配偶的生日是？", q3 = "您的学号（或工号）是？"; // 默认选项
        var items = Array(); // items = []

        function fillDatas(obj, remove1, remove2, selectedItem) {
            obj.empty();

            obj.append("<option></option>");
            for (var i = 0; i < items.length; i++) {
                if (items[i] != remove1 && items[i] != remove2 && items[i] != selectedItem)
                    obj.append("<option value='" + items[i] + "'>" + items[i] + "</option>");
            }

            obj.find("option:selected").get(0).text = selectedItem;
        }



        $("#Question1").ready(function () {
            if ($("#Question1").length == 0)
                return;

            for (var i = 0; i < $("#Question1").get(0).options.length; i++) {
                items[i] = $("#Question1").get(0).options[i].text;
            }

            fillDatas($("#Question1"), q2, q3, q1);
            fillDatas($("#Question2"), q1, q3, q2);
            fillDatas($("#Question3"), q1, q2, q3);
        });


        $("#Question1").bind("click", function () {
            q1 = $("#Question1").get(0).value;
            fillDatas($("#Question2"), q1, q3, q2);
            fillDatas($("#Question3"), q1, q2, q3);
        });

        $("#Question2").bind("click", function () {
            q2 = $("#Question2").get(0).value;
            fillDatas($("#Question1"), q2, q3, q1);
            fillDatas($("#Question3"), q1, q2, q3);
        });

        $("#Question3").bind("click", function () {
            q3 = $("#Question3").get(0).value;
            fillDatas($("#Question1"), q2, q3, q1);
            fillDatas($("#Question2"), q1, q3, q2);
        });
    });
</script>

<h2 style="color: #f00">注：密保问题保存后不可更改！！！若需要更改，请联系客服。</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>修改密保问题</legend>

        @Html.HiddenFor(model => model.LoginName)

        <div class="editor-label">
            @Html.LabelFor(model => model.Question1)
        </div>

        <div class="editor-field">
            @{
    if (ViewBag.isFirst)
    {
                @Html.DropDownListFor(model => model.Question1, ViewBag.QuestionList as IEnumerable<SelectListItem>)
                @Html.ValidationMessageFor(model => model.Question1)
    }
    else
    {
                @Html.DisplayFor(model => model.Question1);
    }
            }
        </div>


        <div class="editor-label">
            @Html.LabelFor(model => model.Answer1)
        </div>
        <div class="editor-field">
            @{
    if (ViewBag.isFirst)
    {
                @Html.EditorFor(model => model.Answer1)
                <span style="color:Red;font-weight:bold">（必填）</span>
                @Html.ValidationMessageFor(model => model.Answer1)
    }
    else
    {
                @Html.DisplayFor(model => model.Answer1)
    }
            }
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Question2)
        </div>
        <div class="editor-field">
            @{
    if (ViewBag.isFirst)
    {
                @Html.DropDownListFor(model => model.Question2, ViewBag.QuestionList as IEnumerable<SelectListItem>)
                @Html.ValidationMessageFor(model => model.Question2)
    }
    else
    {
                @Html.DisplayFor(model => model.Question2)
    }
            }
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Answer2)
        </div>
        <div class="editor-field">
            @{
    if (ViewBag.isFirst)
    {
                @Html.EditorFor(model => model.Answer2)
                <span style="color:Red;font-weight:bold">（必填）</span>
                @Html.ValidationMessageFor(model => model.Answer2)
    }
    else
    {
                @Html.DisplayFor(model => model.Answer2)
    }
            }
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Question3)
        </div>
        <div class="editor-field">
            @{
    if (ViewBag.isFirst)
    {
                @Html.DropDownListFor(model => model.Question3, ViewBag.QuestionList as IEnumerable<SelectListItem>)
                @Html.ValidationMessageFor(model => model.Question3)
    }
    else
    {
                @Html.DisplayFor(model => model.Question3)
    }
            }
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Answer3)
        </div>
        <div class="editor-field">
            @{
    if (ViewBag.isFirst)
    {
                @Html.EditorFor(model => model.Answer3)
                <span style="color:Red;font-weight:bold">（必填）</span>
                @Html.ValidationMessageFor(model => model.Answer3)
    }
    else
    {
                @Html.DisplayFor(model => model.Answer3)
    }
            }
        </div>

        <p>
            @{
    if (ViewBag.isFirst)
    {
                <input type="submit" value="保存" />
    }
            }
        </p>
    </fieldset>
}

<div>
    @Html.ActionLink("返回首页", "Index", "Default")
</div>

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}
@{
    if (ViewBag.Done != null)
    {
    <div id="dialog" title="Dialog Title">
        <h5>
            @{
        if (ViewBag.Done)
        {
                @:修改成功
            }
        else
        {
                @:修改失败
            }
            }
        </h5>
        <div>
            <button onclick="javascript:closedialog()">确定</button>
        </div>
    </div>
    <script type="text/javascript">

        $(document).ready(function () {
            $("#dialog").dialog({ title: "操作提示", modal: true });
        });

        function closedialog() {
            $("#dialog").dialog("close");
        }
    </script>
    }
}
